﻿using LS.Screening.AvaloniaApp.Views;
using LS.Screening.UI.Common.Mvvm;
using ReactiveUI;

namespace LS.Screening.AvaloniaApp.ViewModels
{
    public class LoginWindowViewModel : ViewModelBase
    {
        #region 属性

        string account = "lingshu@163.com";
        /// <summary>
        /// 账号
        /// </summary>
        public string Account { get => account; set => this.RaiseAndSetIfChanged(ref account, value); }

        string password = "Ls1234";
        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get => password; set => this.RaiseAndSetIfChanged(ref password, value); }

        #endregion

        #region Commands及构造

        public IReactiveCommand LoginCommand { get; set; }

        public LoginWindowViewModel()
        {
            this.LoginCommand = ReactiveCommand.Create(Login);
            this.ObserveValues();
        }

        #endregion

        #region 方法

        private void ObserveValues()
        {

        }

        private void Login()
        {
            App.SetCurrentUser(new CurrentLoginUser { Account = this.Account, Password = this.Password });
            MainWindow mainWindow = new MainWindow();
            mainWindow.Show();

            // 关闭当前窗口
            if (App.CurrentWindow is LoginWindow)
            {
                App.CurrentWindow.Close();
            }
            App.SetCurrentWidow(mainWindow);
        }

        private void ChangePassword(string password)
        {

        }

        #endregion
    }
}